//
//  HHHeader.h
//  Pods
//
//  Created by lch on 2021/10/8.
//

#ifndef HHHeader_h
#define HHHeader_h

//屏高宽
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height

//颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b)  RGBA(r,g,b,1.0f)
#define rgbaValue(rgbValue)        [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

// 主题色
#define MainColor rgba(65, 162, 247, 1)


// 字符串不为空
#define HHStringIsNotEmpty(__string)  (!HHStringIsEmpty(__string))
// 字符串为空
#define HHStringIsEmpty(__string) ((__string.length == 0) || HHObjectIsNil(__string) || [__string rangeOfString:@"null"].location != NSNotFound)
// 是否为空对象
#define HHObjectIsNil(__object)  ((nil == __object) || [__object isKindOfClass:[NSNull class]])

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;
// 强引用
#define StrongSelf(weakSelf) __strong typeof(weakSelf) strongSelf = weakSelf;
/** 字体大小 */
#define FONT(FONTSIZE)          [UIFont systemFontOfSize:FONTSIZE]
// 是否是x系列手机
#define kDevice_Is_iPhoneX \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})


#define HHNavHeight   ((kDevice_Is_iPhoneX) ? 88.0 : 64.0)
#define HHTabBarHeight     ((kDevice_Is_iPhoneX) ? 83.0 : 49.0)
#define HHTabBarSafeAreaHeight     ((kDevice_Is_iPhoneX) ? 34.0 : 0.0)
#define HHNavBarSafeAreaHeight       ((kDevice_Is_iPhoneX) ? 44.0 : 20.0)



#pragma clang diagnostic pop
CG_INLINE UIAlertController * _Nullable HH_showAlert(UIViewController * _Nullable vc, NSString * _Nullable title,
        NSString * _Nullable message,
        NSString * _Nullable buttonTitle1,
        NSString * _Nullable buttonTitle2,
        dispatch_block_t _Nullable buttonTitle1Handler,
        dispatch_block_t _Nullable buttonTitle2Handler) {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        UIPopoverPresentationController *pop = [alertController popoverPresentationController];
        pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
        pop.sourceView = vc.view;
        pop.sourceRect = vc.view.bounds;
    }
    
    if (buttonTitle1) {
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:buttonTitle1 style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (buttonTitle1Handler) buttonTitle1Handler();
        }];
        [alertController addAction:cancelAction];
    }
    if (buttonTitle2) {
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:buttonTitle2 style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (buttonTitle2Handler) buttonTitle2Handler();
        }];
        [alertController addAction:okAction];
    }
    [vc presentViewController:alertController animated:YES completion:nil];
    return alertController;
}



#endif /* HHHeader_h */
